package com.copa.utils;

import com.alibaba.fastjson.JSON;
import org.jsoup.Connection;
import org.jsoup.Jsoup;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

public class OkHttpUtil {
    private static final Logger LOG = LoggerFactory.getLogger(OkHttpUtil.class);

    public static void sendMessage(String wxid_to,String msg) throws IOException {
        Map<String, String> dataMap = new HashMap<>();
        dataMap.put("api", "SendTextMsg");
        dataMap.put("robot_wxid", wxid_to);
        dataMap.put("to_wxid", wxid_to);
        dataMap.put("msg", msg);
        String json = JSON.toJSONString(dataMap);
        Jsoup.connect("http://127.0.0.1:88/httpAPI")
                .header("Accept", "application/json, text/plain, */*")
                .header("Content-Type", "application/json;charset=UTF-8")
                .method(Connection.Method.POST)
                .ignoreContentType(true)
                .data(dataMap)
                .requestBody(json)
                .execute().body();
        //LOG.info();
    }
}
